package modules.scripts;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

import com.beust.jcommander.JCommander;

import miscellaneous.Couple;
import miscellaneous.JCommanderUsageWrapper;
import miscellaneous.Pillar;
import miscellaneous.Sequence;
import miscellaneous.SequenceFileWriter;
import miscellaneous.SimpleFileIO;
import miscellaneous.Species;
import modules.HomoCompara;

public class Scripts implements HomoCompara {

	public String getModuleName() {
		return "scripts";
	}

	public void main(String[] args) throws Exception {
		Parameters params;
		String path;
		String output;
		String fileName;
		String syntenyFile;
		String testFile;
		String script;
		String software1;
		String software2;
		String pillar;
		String sequenceFile;

		 try {

			 // ================ PARSE USER OPTIONS AND ARGUMENTS ================

			 params = new Parameters();
			 JCommander jc = new JCommander(params, args);

			 if (args.length == 0 || params.help) {
				 StringBuilder sb = new StringBuilder(65536);
				 sb.append(
						 "================================================================================\n" +
								 "Scripts is ........... \n\n" +
								 "If you use this program in your research or for comparison reasons, please cite the \n" +
								 "following articles.\n" +
								 "References:\n" +
								 "    HomoCompara : A Comparative Study of Homology Inference Techniques and Methodologies \n" +
								 "    on Eukaryotic, Fungi, Bacteria and Simulated Datasets,\n" +
								 "    Ali RH, Muhammad SA and Lars Arvestad, 2014, doi: .................\n\n" +
								 "Releases, source code and tutorial: http://code.google.com/p/homocompara/\n\n" +
								 "License: GenFamClust is available under the New BSD License.\n" +
						 "================================================================================\n");
				 sb.append("Usage:\n" +
						 "    java -jar homocompara-X.Y.Z.jar scripts [options] <args>\n");
				 sb.append("--------------------------------------------------------------------------------\n" +
						 "Available script ShortList : Complete Name\n" +
						 "CBR  : CorrectBlastResults(path, fileName, output)\n" +
						 "CC   : ClusterCleaner(path, fileName, output)\n" +
						 "CR   : CorrectingResults(path, fileName, output)\n" +
						 "MYTM : MakeYeastTestMap(path, fileName, syntenyFile, output)\n" +
						 "YTFC : YeastTestFamilyCounter(path, fileName, output)\n" +
						 "ESTD : ExtractSyCPairsForTestData(path, fileName, testFile, output)\n" +
						 "PTD  : PrepareTestDataset(path, fileName, syntenyFile, output)\n" +
						 "QQNM : QueryQueryForNCMultiSpec(path, fileName, output)\n" +
						 "QQSS : QueryQueryScoreSeperator(path, fileName, output)\n" +
						 "YSPM : YeastSequenceToPillarMatch(path, fileName, syntenyFile, output)\n" +
						 "EEFB : ExtractEvaluesFromBlast(path, fileName, output)\n" +
						 "EBFB : ExtractBitScoresFromBlast(path, fileName, output)\n" +
						 "PGSD : PrepareGeneMapForSimulatedData(path, fileName, syntenyFile, output)\n" + 
						 "CS   : ClusterSeparator(path, testFile, fileName, output)\n" +
						 "CIDN : ConvertIndexToDataName(path, syntenyFile, fileName, output)\n" +
						 "CDNI : ConvertDataNameToIndex(path, syntenyFile, fileName, output)\n" +
						 "GSP  : GenerateSequencePairs(path, fileName, output)\n" +
						 "CSPS : CompareSequencePairsFromTwoSoftware(path, fileName, software1, software2, output)\n" +
						 "SCFG : SeparateClustersFromGraphicalFormat(path, testFile, fileName, output)\n" +
						 "CSCB : ConvertGraphicalClustersToBlastClust(path, fileName, output)\n" +
						 "MYPO : ManagingYeastPillarsOriginal(path, syntenyFile, pillarFileName, syntenyScoreFile, output)\n" +
						 "MSIN : MapSyntenyIndexesToNames(path, fileName, output)\n" +
						 "CYPE : ComparingYeastPillarsWithEvaluated(path, syntenyFile, pillarFileName, evaluatedScoreFile, output)\n" +
						 "CPUG : ConstructPillarsUsingGFC(path, evaluatedFile, output)\n" +
						 "CTCS : CompareTwoClustersFromSoftware(path, software1, software2, output)\n" +
						 "EHMC : ExtractHumanMouseClusters(path, fileName, output)\n" + 
						 "DDP : DrawDotPlot(path, syntenyFile, software1, software2, output)\n" + 
						 "GSFI : GetSequenesFromIdentifier(path, fileName, sequenceFile, output)\n" +
						 "DYPM : DetermineYeastPillarMatching(path, software1, software2, output)\n" +
						 "DAHC : DetermineAPBHomologyClusters(path, fileName, output)\n" +
						 "AQQB : APBQueryQueryBlast(path, fileName, output)\n" +
						 "SGSC : SimulatedDataGoldStandardConverter(path, syntenyFile, fileName, output)\n" +
						 "PHTF : PrepareHashimsTestFormatFiles(path, syntenyFile, fileName, output)\n" +
						 "GPFC : GeneratePairsFromClusters(path, fileName, output)\n" +
						 "CTPF : CompareTwoPairsFiles(path, software1, software2, output)\n" +
						 "ENSH : ExtractNCSpeciesHits(path, fileName, output)\n" + 
						 "ANCT : ApplyNCThreshold(path, fileName, output)\n" +
						 "--------------------------------------------------------------------------------\n\n");
				 
				 JCommanderUsageWrapper.getUnsortedUsage(jc, params, sb);
				 System.out.println(sb.toString());
				 return;
			 }

			 script = params.script.get(0);
			 path = params.path;
			 output = params.output;
			 fileName = params.file;
			 syntenyFile = params.synteny;
			 testFile = params.test;
			 software1 = params.software1;
			 software2 = params.software2;
			 pillar = params.pillar;
			 sequenceFile = params.sequenceFile;

			 if(!path.endsWith("/"))
				 path = path.concat("/");

			 if(script.equalsIgnoreCase("CBR")) 
				 CorrectBlastResults(path, fileName, output);
			 else if(script.equalsIgnoreCase("CC")) 
				 ClusterCleaner(path, fileName, output);
			 else if(script.equalsIgnoreCase("CR")) 
				 CorrectingResults(path, fileName, output);
			 else if(script.equalsIgnoreCase("MYTM")) 
				 MakeYeastTestMap(path, fileName, syntenyFile, output);
			 else if(script.equalsIgnoreCase("YTFC")) 
				 YeastTestFamilyCounter(path, fileName, output);
			 else if(script.equalsIgnoreCase("ESTD")) 
				 ExtractSyCPairsForTestData(path, fileName, testFile, output);
			 else if(script.equalsIgnoreCase("PTD")) 
				 PrepareTestDataset(path, fileName, syntenyFile, output);
			 else if(script.equalsIgnoreCase("QQNM")) 
				 QueryQueryForNCMultiSpec(path, fileName, output);
			 else if(script.equalsIgnoreCase("QQSS")) 
				 QueryQueryScoreSeperator(path, fileName, output);
			 else if(script.equalsIgnoreCase("YSPM")) 
				 YeastSequenceToPillarMatch(path, fileName, syntenyFile, output);
			 else if(script.equalsIgnoreCase("EEFB"))
				 ExtractEvaluesFromBlast(path, fileName, output);
			 else if(script.equalsIgnoreCase("EBFB"))
				 ExtractBitScoresFromBlast(path, fileName, output);
			 else if(script.equalsIgnoreCase("PGSD"))
				 PrepareGeneMapForSimulatedData(path, fileName, syntenyFile, output);
			 else if(script.equalsIgnoreCase("CS"))
				 ClusterSeparator(path, testFile, fileName, output);
			 else if(script.equalsIgnoreCase("CIDN"))
				 ConvertIndexToDataName(path, syntenyFile, fileName, output);
			 else if(script.equalsIgnoreCase("CDNI"))
				 ConvertDataNameToIndex(path, syntenyFile, fileName, output);
			 else if(script.equalsIgnoreCase("GSP"))
				 GenerateSequencePairs(path, fileName, output);
			 else if(script.equalsIgnoreCase("CSPS"))
				 CompareSequencePairsFromTwoSoftware(path, fileName, software1, software2, output);
			 else if(script.equalsIgnoreCase("SCFG"))
			 	SeparateClustersFromGraphicalFormat(path, testFile, fileName, output);
			 else if(script.equalsIgnoreCase("CSCB"))
				 ConvertGraphicalClustersToBlastClust(path, fileName, output);
			 else if (script.equalsIgnoreCase("MYPO"))
			 	ManagingYeastPillarsOriginal(path, syntenyFile, pillar, fileName, output);
			 else if (script.equalsIgnoreCase("MSIN"))
				 MapSyntenyIndexesToNames(path, fileName, output);
			 else if (script.equalsIgnoreCase("CYPE"))
				 ComparingYeastPillarsWithEvaluated(path, syntenyFile, pillar, fileName, output);
			 else if (script.equalsIgnoreCase("CPUG"))
				 ConstructPillarsUsingGFC(path, fileName, output);
			 else if (script.equalsIgnoreCase("CTCS"))
				 CompareTwoClustersFromSoftware(path, software1, software2, output);
			 else if (script.equalsIgnoreCase("EHMC"))
				 ExtractHumanMouseClusters(path, fileName, output);
			 else if (script.equalsIgnoreCase("DDP"))
				 DrawDotPlot(path, syntenyFile, software1, software2, output);
			 else if(script.equalsIgnoreCase("GSFI"))
				 getSequenesFromIdentifier(path, fileName, sequenceFile, output);
			 else if(script.equalsIgnoreCase("DYPM"))
				 DetermineYeastPillarMatching(path, software1, software2, output);
			 else if(script.equalsIgnoreCase("DAHC"))
				 DetermineAPBHomologyClusters(path, fileName, output);
			 else if(script.equalsIgnoreCase("AQQB"))
				 APBQueryQueryBlast(path, fileName, output);
			 else if(script.equalsIgnoreCase("SGSC"))
				 SimulatedDataGoldStandardConverter(path, syntenyFile, fileName, output);
			 else if(script.equalsIgnoreCase("PHTF"))
				 PrepareHashimsTestFormatFiles(path, syntenyFile, fileName, output);
			 else if(script.equalsIgnoreCase("GPFC"))
				 GeneratePairsFromClusters(path, fileName, output);
			 else if(script.equalsIgnoreCase("CTPF"))
				 CompareTwoPairsFiles(path, software1, software2, output);
			 else if(script.equalsIgnoreCase("ENSH"))
				 ExtractNCSpeciesHits(path, fileName, output);
			 else if(script.equalsIgnoreCase("ANCT"))
				 ApplyNCThreshold(path, fileName, output);
		 } catch (Exception e) {
			 System.out.println("Scripts Failed : " + e.getMessage());
			 System.exit(-1);
		 }		
	}
	
	public void CorrectBlastResults(String path, String fileName, String output) {
		BufferedReader bufferedreader;
		String str;
		int count = 0;

		try {
			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split("\t");
				String[] strArr1 = strArr[0].split("\\.");
				String spec1 = strArr1[0];
				String[] strArr2 = strArr[1].split("\\.");
				String spec2 = strArr2[0];
				
				if(strArr1[0].equals("7"))
					spec1 = "17";
				else if(strArr1[0].equals("10"))
					spec1 = "18";
				else if(Integer.parseInt(strArr1[0]) > 7 && Integer.parseInt(strArr1[0]) < 10) 
					spec1 = String.valueOf(Integer.parseInt(strArr1[0]) - 1);
				else if(Integer.parseInt(strArr1[0]) > 10) 
					spec1 = String.valueOf(Integer.parseInt(strArr1[0]) - 2);
				
				if(strArr2[0].equals("7")) 
					spec2 = "17";
				else if(strArr2[0].equals("10")) 
					spec2 = "18";
				else if(Integer.parseInt(strArr2[0]) > 7 && Integer.parseInt(strArr2[0]) < 10) 
					spec2 = String.valueOf(Integer.parseInt(strArr2[0]) - 1);
				else if (Integer.parseInt(strArr2[0]) > 10) 
					spec2 = String.valueOf(Integer.parseInt(strArr2[0]) - 2);
				
				for(int i = 0; i < strArr.length; i++) {
					if(i == 0)
						SequenceFileWriter.writeAndAppendString(path, output, spec1 + "." + strArr1[1] + "." + strArr1[2]);
					else if (i==1)
						SequenceFileWriter.writeAndAppendString(path, output, "\t" + spec2 + "." + strArr2[1] + "." + strArr2[2]);
					else
						SequenceFileWriter.writeAndAppendString(path, output, "\t" + strArr[i]);
				}
				SequenceFileWriter.writeAndAppendString(path, output, "\n");
				count++;
				if(count%50000 == 0) 
					System.out.println(str + " : " + spec1 + "." + strArr1[1] + "." + strArr1[2] + "\t" + spec2 + "." + strArr2[1] + "." + strArr2[2]);
			}
			bufferedreader.close();
		} catch (Exception e) {
			System.out.println("CorrectBlastResults failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void ClusterCleaner(String path, String fileName, String output) {
		try {
			BufferedReader bufferedreader;
			String str;

			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) { 
				if(!str.equals(""))
					SequenceFileWriter.writeAndAppendLine(path, output, str);
			}
		} catch (Exception e) {
			System.out.println("ClusterCleaner failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void CorrectingResults(String path, String fileName, String output) {
		try {
			BufferedReader bufferedreader;
			String str;

			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split("\t");
				if(strArr.length == 1)
					SequenceFileWriter.writeAndAppendLine(path, output, str);
			}
			bufferedreader.close();
		} catch (Exception e) {
			System.out.println("CorrectingResults failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void MakeYeastTestMap(String path, String fileName, String syntenyFile, String output) {
		try {
			String str;
			BufferedReader bufferedreader;
			
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSyntenyFile(path, syntenyFile);
			ArrayList<Species> speciesList = reader.getSpeciesList();

			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			int count = -1;
			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split("\t");
				count++;
				for(int i = 0; i < strArr.length; i++) {
					String[] strArr1 = strArr[i].split("\\.");
					SequenceFileWriter.writeAndAppendLine(path, output, speciesList.get(Integer.parseInt(strArr1[0])).getChromosomes().get(Integer.parseInt(strArr1[1])).getGeneList().get(Integer.parseInt(strArr1[2])).getGeneID() + "\t" + strArr[i] + "\t" + count);
				}
			}
			bufferedreader.close();
		} catch (Exception e) {
			System.out.println("MakeYeastTestMap Failed : " + e.getMessage()); 
			System.exit(-1);
		}
	}
	
	public void YeastTestFamilyCounter(String path, String fileName, String output) {
		String str;
		BufferedReader bufferedreader;
		int count = 0;
		try {
			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split("\t");
				SequenceFileWriter.writeAndAppendString(path, output, strArr.length + ", ");
				count++;
				if(count%25 == 0)
					SequenceFileWriter.writeAndAppendString(path, output, "\n");
			}
		} catch (Exception e) {
			System.out.println("YeastTestFamilyCounter Failed : " + e.getMessage()); 
			System.exit(-1);
		}

	}

	public void ExtractSyCPairsForTestData(String path, String fileName, String testFile, String output) {
		try {
			String str;
			BufferedReader bufferedreader;
			ArrayList<String> genes = new ArrayList<String>(); 
			
			bufferedreader = new BufferedReader(new FileReader(path + testFile));
			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split("\t");
				genes.add(strArr[1]);
			}
			bufferedreader.close();
			
			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split("\t");
				boolean check1 = false;
				boolean check2 = false;
				for(int i = 0; i < genes.size(); i++) {
					if(check1 == true && check2 == true) {
						SequenceFileWriter.writeAndAppendLine(path, output, str);
						break;
					} 
					
					if(check1 != true && strArr[0].equals(genes.get(i))) 
						check1 = true;
					if(check2 != true && strArr[1].equals(genes.get(i))) 
						check2 = true;
				}
			}
		} catch (Exception e) {
			System.out.println("ExtractSyCPairsForTestData Failed : " + e.getMessage()); 
			System.exit(-1);
		}
	}
	
	public void PrepareTestDataset(String path, String fileName, String syntenyFile, String output) {
		ArrayList<String> familygene = new ArrayList<String>();
		ArrayList<String> protID = new ArrayList<String>();

		BufferedReader bufferedreader;
		String str;

		try {
			bufferedreader = new BufferedReader(new FileReader(path + fileName));

			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				familygene.add(strArr[3]);
				protID.add(strArr[1]);
			}
			bufferedreader.close();

			SimpleFileIO reader = new SimpleFileIO();
			reader.readSyntenyFile(path, syntenyFile);

			ArrayList<Species> species = reader.getSpeciesList();
			int check = 0;

			for(int i = 0; i < protID.size(); i++) {
				String gene = protID.get(i);
				check = -1;
				outerloop:
					for(int j = 0; j < species.size(); j++) {
						for(int k = 0; k < species.get(j).getChromosomes().size(); k++) {
							for(int l = 0; l < species.get(j).getChromosomes().get(k).getGeneList().size(); l++) {
								String prot = species.get(j).getChromosomes().get(k).getGeneList().get(l).getGeneID();
								String index = species.get(j).getChromosomes().get(k).getGeneList().get(l).getIndex();
								if(gene.equals(prot)) {
									SequenceFileWriter.writeAndAppendLine(path, output, prot + "\t" + index + "\t" + familygene.get(i));
									check = j;
									break outerloop;
								}
							}
						}
					}
				if(check == -1) 
					System.out.println(gene);
			}
		} catch (Exception e) {
			System.out.println("prepareTestDataset Failed : " + e.getMessage()); 
			System.exit(-1);
		}
	}
	
	public void QueryQueryForNCMultiSpec(String path, String fileName, String output) {
		try {
			BufferedReader bufferedreader = new BufferedReader(new FileReader(path + fileName));
			String str;

			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split(" ");
				if(Double.parseDouble(strArr[2]) > 0.5) {
					if(strArr[0].startsWith("7.") && strArr[1].startsWith("7.")) {
						String[] strArr1 = strArr[0].split("\\.");
						String[] strArr2 = strArr[1].split("\\.");
						SequenceFileWriter.writeAndAppendLine(path, output, 17 + "." + strArr1[1] + "." + strArr1[2] + "\t" + 17 + "." + strArr2[1] + "." + strArr2[2] + "\t" + strArr[2]);
					} else if(strArr[0].startsWith("7.") && strArr[1].startsWith("10.")) {
						String[] strArr1 = strArr[0].split("\\.");
						String[] strArr2 = strArr[1].split("\\.");
						SequenceFileWriter.writeAndAppendLine(path, output, 17 + "." + strArr1[1] + "." + strArr1[2] + "\t" + 18 + "." + strArr2[1] + "." + strArr2[2] + "\t" + strArr[2]);
					} else if(strArr[0].startsWith("10.") && strArr[1].startsWith("7.")) {
						String[] strArr1 = strArr[0].split("\\.");
						String[] strArr2 = strArr[1].split("\\.");
						SequenceFileWriter.writeAndAppendLine(path, output, 18 + "." + strArr1[1] + "." + strArr1[2] + "\t" + 17 + "." + strArr2[1] + "." + strArr2[2] + "\t" + strArr[2]);
					} else if(strArr[0].startsWith("10.") && strArr[1].startsWith("10.")) {
						String[] strArr1 = strArr[0].split("\\.");
						String[] strArr2 = strArr[1].split("\\.");
						SequenceFileWriter.writeAndAppendLine(path, output, 18 + "." + strArr1[1] + "." + strArr1[2] + "\t" + 18 + "." + strArr2[1] + "." + strArr2[2] + "\t" + strArr[2]);
					}
				}
			}
		} catch (Exception e) {
			System.out.println("QueryQueryForNCMultiSpec Failed : " + e.getMessage()); 
			System.exit(-1);
		}
	}
	
	public void QueryQueryScoreSeperator(String path, String fileName, String output) {
		try {
			BufferedReader bufferedreader = new BufferedReader(new FileReader(path + fileName));
			String str;

			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split(" ");
				if(strArr[0].startsWith("7.") || strArr[1].startsWith("7.") || strArr[0].startsWith("10.") || strArr[1].startsWith("10.")) 
					SequenceFileWriter.writeAndAppendLine(path, output, strArr[0] + " " + strArr[1] + " " + strArr[2]);
			}
		} catch (Exception e) {
			System.out.println("QueryQueryScoreSeperator failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void YeastSequenceToPillarMatch(String path, String fileName, String syntenyFile, String output) {
		try {
			ArrayList<Species> species = new ArrayList<Species>();
			
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSyntenyFile(path, syntenyFile);
			species = reader.getSpeciesList();
			
			BufferedReader bufferedreader;
			String str;

			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split("\t");
				for(int i = 0; i < strArr.length; i++) {
					boolean check = true;
					if(strArr[i].equals("---")) {
						if(i == 0)
							SequenceFileWriter.writeAndAppendString(path, output, "-");
						else
							SequenceFileWriter.writeAndAppendString(path, output, "\t-");
					} else {
						outerloop:
							for(int j = 0; j < species.size(); j++) {
								for(int k = 0; k < species.get(j).getChromosomes().size(); k++) {
									for(int l = 0; l < species.get(j).getChromosomes().get(k).getGeneList().size(); l++) {
										if(species.get(j).getChromosomes().get(k).getGeneList().get(l).getGeneID().equals(strArr[i])) {
											if(i == 0)
												SequenceFileWriter.writeAndAppendString(path, output, species.get(j).getChromosomes().get(k).getGeneList().get(l).getIndex());
											else
												SequenceFileWriter.writeAndAppendString(path, output, "\t" + species.get(j).getChromosomes().get(k).getGeneList().get(l).getIndex());
											check = false;
											break outerloop;
										}
									}
								}
							}
						if(check == true)
							System.out.println(strArr[i]);
					}
				}
				SequenceFileWriter.writeAndAppendLine(path, output, "");
			}
		} catch (Exception e) {
			System.out.println("YeastSequenceToPillarMatch failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void ExtractEvaluesFromBlast(String path, String fileName, String output) {
		try {
			BufferedReader bufferedreader;
			String str;

			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split("\t");
				SequenceFileWriter.writeAndAppendLine(path, output, strArr[0] + "\t" + strArr[1] + "\t" + strArr[10]);
			}
		} catch (Exception e) {
			System.out.println("ExtractEvaluesFromBlast failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void ExtractBitScoresFromBlast(String path, String fileName, String output) {
		try {
			BufferedReader bufferedreader;
			String str;
			int count = 0;

			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) { 
				count++;
				String[] strArr = str.split("\t");
				SequenceFileWriter.writeAndAppendLine(path, output, strArr[0].replaceAll("\\s", "") + " " + strArr[1].replaceAll("\\s", "") + " " + strArr[11].replaceAll("\\s", ""));
				if (count%100000==1)
					System.out.println("Count = " + count);
			}
		} catch (Exception e) {
			System.out.println("ExtractBitScoresFromBlast failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void PrepareGeneMapForSimulatedData(String path, String fileName, String syntenyFile, String output) {
		try {
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSyntenyFile(path, syntenyFile);
			ArrayList<Species> species = reader.getSpeciesList();
			
			BufferedReader bufferedreader;
			String str;

			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split("\t");
				int count = 0;
				for(int i = 0; i < strArr.length; i++) {
					String[] data = strArr[i].split("\\/");
					String gene = data[1];
					String spec = data[0] + "_G";
					String gen1 = "";
					for(int j = 0; j < gene.length(); j++) {
						if(gene.charAt(j) != '0') {
							gen1 = gene.substring(j);
							break;
						}
					}
					gene = spec + gen1;
					boolean check = false;
					
					outerloop:
						for(int j = 0; j < species.size(); j++) {
							for(int k = 0; k < species.get(j).getChromosomes().size(); k++) {
								for(int l = 0; l < species.get(j).getChromosomes().get(k).getGeneList().size(); l++) {
									if(species.get(j).getChromosomes().get(k).getGeneList().get(l).getGeneID().equals(gene)) {
										if(count == 0) 
											SequenceFileWriter.writeAndAppendString(path, output, species.get(j).getChromosomes().get(k).getGeneList().get(l).getIndex());
										else
											SequenceFileWriter.writeAndAppendString(path, output, "\t" + species.get(j).getChromosomes().get(k).getGeneList().get(l).getIndex());
										count++;
										check = true;
										break outerloop;
									}
								}
							}
						}
					if(check == false) {
						System.out.println("Not found : " + gene );
					}
				}
				SequenceFileWriter.writeAndAppendLine(path, output, "");
			}
		} catch (Exception e) {
			System.out.println("ExtractBitScoresFromBlast failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public static ArrayList<Couple<String, Integer>> getFamilyMaps(ArrayList<String> family) {
		ArrayList<Couple<String, Integer>> familyMap = new ArrayList<Couple<String, Integer>>();
		int count = 0;
		for(int i = 0; i < family.size(); i++) {
			boolean check = false;
			for(int j = 0; j < familyMap.size(); j++) {
				if(familyMap.get(j).first.equals(family.get(i))) {
					check = true;
					break;
				}
			}
			if(check == false) {
				familyMap.add(new Couple<String, Integer>(family.get(i), count));
				count++;
			}
		}
		return familyMap;
	}
	
	public static Integer getIndex(ArrayList<Couple<String, Integer>> familyMaps, String family) {
		for(int i = 0; i < familyMaps.size(); i++) {
			if(familyMaps.get(i).first.equals(family)) {
				return familyMaps.get(i).second;
			}
		}
		return -1;
	}
	
	public static void ClusterSeparator(String path, String testFile, String clusterFile, String output) {
		try {
			BufferedReader bufferedreader;
			String str;
			ArrayList<String> geneIndex = new ArrayList<String>();
			ArrayList<String> family = new ArrayList<String>();

			bufferedreader = new BufferedReader(new FileReader(path + testFile));
			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				geneIndex.add(strArr[1]);
				family.add(strArr[2]);
			}
			bufferedreader.close();
			
			ArrayList<Couple<String, Integer>> familyMaps = getFamilyMaps(family);

			bufferedreader = new BufferedReader(new FileReader(path + clusterFile));
			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				int count = 0;
				for(int i = 0; i < strArr.length; i++) {
					String index = strArr[i];
					for(int j = 0; j < geneIndex.size(); j++) {
						if(geneIndex.get(j).equals(index) && count == 0) {
							SequenceFileWriter.writeAndAppendString(path, output + ".bcl", index);
							SequenceFileWriter.writeAndAppendString(path, output + "_Fam.bcl", String.valueOf(getIndex(familyMaps, family.get(j))));
							count++;
							break;
						} else if(geneIndex.get(j).equals(index) && count > 0) {
							SequenceFileWriter.writeAndAppendString(path, output + ".bcl", "\t" + index);
							SequenceFileWriter.writeAndAppendString(path, output + "_Fam.bcl" , "\t" + String.valueOf(getIndex(familyMaps, family.get(j))));
							break;
						}
					}
				}
				if(count>0) {
					SequenceFileWriter.writeAndAppendString(path, output + ".bcl", "\n");
					SequenceFileWriter.writeAndAppendString(path, output + "_Fam.bcl" , "\n");
				}
			}
			bufferedreader.close();
		} catch (Exception e) {
			System.out.println("clusterSeparator failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public static void ClusterSeparatorFromgraphicsFile(String path, String mapFileName, String graphFileName, String output) {
		try {
			String str;
			int count = -1;
			BufferedReader bufferedreader;
			ArrayList<String> lines = new ArrayList<String>();
			ArrayList<ArrayList<String>> families = new ArrayList<ArrayList<String>>();
			String currentFamily = "";
			bufferedreader = new BufferedReader(new FileReader(path + mapFileName));
			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				if(currentFamily.equals(strArr[2])) {
					families.get(count).add(strArr[1]);
				} else {
					ArrayList<String> family = new ArrayList<String>();
					family.add(strArr[1]);
					families.add(family);
					currentFamily = strArr[2];
					count++;
				}
			}
			bufferedreader.close();

			bufferedreader = new BufferedReader(new FileReader(path + graphFileName));
			while ((str = bufferedreader.readLine()) != null) {
				if(str.startsWith("<?xml") || str.startsWith("<gexf") || str.startsWith("\t<meta") || str.startsWith("\t\t<creator") || str.startsWith("\t\t<creator") || str.startsWith("\t</meta") || str.startsWith("</gexf")) {
					continue;
				} else if(str.startsWith("\t\t</nodes")) {
					while (!(str = bufferedreader.readLine()).startsWith("\t\t</edges")) {
						continue;
					}
				} else if(!str.startsWith("\t</graph")) {
					lines.add(str);
				} else {
					lines.add(str);
					boolean check = false;

					outerloop:
						for(int i = 0; i < lines.size(); i++) {
							if(lines.get(i).startsWith("\t\t\t<node id=\"")) {
								for(int j = 0; j < families.size(); j++) {
									for(int k = 0; k < families.get(j).size(); k++) {
										if(lines.get(i).startsWith("\t\t\t<node id=\"" + families.get(j).get(k) + "\"")) {
											System.out.println("Cluster member " + families.get(j).get(k) + " found");
											check = true;
											break outerloop;
										}
									}
								}
							}
						}

					if(check == true) {
						for(int i = 0; i < lines.size(); i++) {
							boolean checker = false;
							if(lines.get(i).startsWith("\t\t\t<node id=\"")) {
								outerloop:
									for(int j = 0; j < families.size(); j++) {
										for(int k = 0; k < families.get(j).size(); k++) {
											if(lines.get(i).startsWith("\t\t\t<node id=\"" + families.get(j).get(k) + "\"")) {
												SequenceFileWriter.writeAndAppendString(path, output, j + "\t");
												i++;
												i++;
												i++;
												i++;
												checker = true;
												break outerloop;
											}
										}
									}
								if(checker == false) {
									i++;
									i++;
									i++;
									i++;
								}
							} 
						}
						SequenceFileWriter.writeAndAppendLine(path, output, "");
					}
					while(lines.size()!= 0) 
						lines.remove(0);
				} 
			}
			bufferedreader.close();
		} catch (Exception e) {
			System.out.println("clusterSeparatorFromgraphicsFile failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void ConvertIndexToDataName(String path, String syntenyFile, String fileName, String output) {
		try{
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSyntenyFile(path, syntenyFile);
			System.out.println("File read");
			ArrayList<Species> speciesList = reader.getSpeciesList();
			
			BufferedReader bufferedreader;
			String str;
			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			
			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				String[] strArr1 = strArr[0].split("\\.");
				int spec1 = Integer.parseInt(strArr1[0]);
				int chr1 = Integer.parseInt(strArr1[1]);
				int gene1 = Integer.parseInt(strArr1[2]);
				SequenceFileWriter.writeAndAppendString(path, output, speciesList.get(spec1).getChromosomes().get(chr1).getGeneList().get(gene1).getGeneID());
				for(int i = 1; i < strArr.length; i++) {
					strArr1 = strArr[i].split("\\.");
					spec1 = Integer.parseInt(strArr1[0]);
					chr1 = Integer.parseInt(strArr1[1]);
					gene1 = Integer.parseInt(strArr1[2]);
					SequenceFileWriter.writeAndAppendString(path, output, "\t" + speciesList.get(spec1).getChromosomes().get(chr1).getGeneList().get(gene1).getGeneID());
				}
				SequenceFileWriter.writeAndAppendLine(path, output, "");

			}
		} catch(Exception e) {
			System.out.println("ConvertIndexToDataName failed : " + e.getMessage());
			System.exit(-1);
		}
	}

	public void ConvertDataNameToIndex(String path, String syntenyFile, String fileName, String output) {
		try{
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSyntenyFile(path, syntenyFile);
			System.out.println("File read");
			ArrayList<Species> speciesList = reader.getSpeciesList();

			BufferedReader bufferedreader;
			String str;
			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			boolean space = false;

			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				if(strArr.length == 1) {
					strArr = str.split(" ");
					space = true;
				}
				boolean spec1 = false;
				boolean spec2 = false;
				String species1 = "";
				String species2 = "";
				
				for(int i = 0; i < speciesList.size(); i++) {
					for(int j = 0 ; j < speciesList.get(i).getChromosomes().size(); j++) {
						for(int k = 0; k < speciesList.get(i).getChromosomes().get(j).getGeneList().size(); k++) {
							if(strArr[0].equals(speciesList.get(i).getChromosomes().get(j).getGeneList().get(k).getGeneID())) {
								spec1 = true;
								species1 = speciesList.get(i).getChromosomes().get(j).getGeneList().get(k).getIndex();
							}
							if(strArr[1].equals(speciesList.get(i).getChromosomes().get(j).getGeneList().get(k).getGeneID())) {
								spec2 = true;
								species2 = speciesList.get(i).getChromosomes().get(j).getGeneList().get(k).getIndex();
							}
							if(spec1 == true && spec2 == true) 
								break;
						}
					}
				}
				if(spec1 == false || spec2 == false) {
					System.out.println("Data name not found in synteny File: " + strArr[0] + "\t" + strArr[1]);
					System.exit(-1);
				}
				if(space == false) {
					SequenceFileWriter.writeAndAppendString(path, output, species1 + "\t" + species2);
					for(int i = 2; i < strArr.length; i++)
						SequenceFileWriter.writeAndAppendString(path, output, "\t" + strArr[i]);
					SequenceFileWriter.writeAndAppendLine(path, output, "");
				} else {
					SequenceFileWriter.writeAndAppendString(path, output, species1 + " " + species2);
					for(int i = 2; i < strArr.length; i++)
						SequenceFileWriter.writeAndAppendString(path, output, " " + strArr[i]);
					SequenceFileWriter.writeAndAppendLine(path, output, "");					
				}
			}
		} catch(Exception e) {
			System.out.println("ConvertDataNameToIndex failed : " + e.getMessage());
			System.exit(-1);
		}	
	}
	
	public void GenerateSequencePairs(String path, String fileName, String output) {
		try {
			String str;
			BufferedReader bufferedreader;
			ArrayList<String> index = new ArrayList<String>();
			ArrayList<String> family = new ArrayList<String>();
		
			bufferedreader = new BufferedReader(new FileReader(path + fileName));

			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				index.add(strArr[1]);
				family.add(strArr[2]);
			}
			
			for(int i = 0; i < index.size(); i++) {
				String family1 = family.get(i);
				String index1 = index.get(i);
				for(int j = i + 1; j < index.size(); j++) {
					if(family1.equals(family.get(j))) 
						SequenceFileWriter.writeAndAppendLine(path, output, index1 + "\t" + index.get(j) + "\t" + family1 + "\t" + family1 + "\t" + 1);
					else 
						SequenceFileWriter.writeAndAppendLine(path, output, index1 + "\t" + index.get(j) + "\t" + family1 + "\t" + family.get(j) + "\t" + 0);
				}
			}
		} catch (Exception e) {
			System.out.println("GenerateSequencePairs failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void CompareSequencePairsFromTwoSoftware(String path, String fileName, String software1, String software2, String output) {
		try {
			String str;
			BufferedReader bufferedreader;
			ArrayList<String> software1family = new ArrayList<String>();
			ArrayList<String> software2family = new ArrayList<String>();
		
			bufferedreader = new BufferedReader(new FileReader(path + software1));

			while ((str = bufferedreader.readLine()) != null) {
				software1family.add(str);
			}
			bufferedreader.close();
			
			bufferedreader = new BufferedReader(new FileReader(path + software2));
			while ((str = bufferedreader.readLine()) != null) {
				software2family.add(str);
			}
			bufferedreader.close();
			
			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				boolean seq1 = false;
				boolean seq2 = false;
				
				for(int i = 0; i < software1family.size(); i++) {
					if(software1family.get(i).contains(strArr[0] + "\t") || software1family.get(i).endsWith(strArr[0])) {
						if(software1family.get(i).contains(strArr[1] + "\t") || software1family.get(i).endsWith(strArr[1])) {
							seq1 = true;
						} else {
							break;
						}
					} else if(software1family.get(i).contains(strArr[1] + "\t") || software1family.get(i).endsWith(strArr[1])) {
						break;
					}
				}
				
				for(int i = 0; i < software2family.size(); i++) {
					if(software2family.get(i).contains(strArr[0] + "\t") || software2family.get(i).endsWith(strArr[0])) {
						if(software2family.get(i).contains(strArr[1] + "\t") || software2family.get(i).endsWith(strArr[1])) {
							seq2 = true;
						} else {
							break;
						}
					} else if(software2family.get(i).contains(strArr[1] + "\t") || software2family.get(i).endsWith(strArr[1])) {
						break;
					}
				}
				
				int truth = Integer.parseInt(strArr[4]);
				if(seq1 == true && seq2 == true) {
					SequenceFileWriter.writeAndAppendLine(path, output, str + "\t" + 1 + "\t" + 1);
					if(truth == 1) 
						SequenceFileWriter.writeAndAppendLine(path, "PosAgreedByBoth" + output, str + "\t" + 1 + "\t" + 1);
					else 
						SequenceFileWriter.writeAndAppendLine(path, "NegDisagreedByBoth" + output, str + "\t" + 1 + "\t" + 1);
				}
				else if(seq1 == true && seq2 == false) {
					SequenceFileWriter.writeAndAppendLine(path, output, str + "\t" + 1 + "\t" + 0);
					if(truth == 1) 
						SequenceFileWriter.writeAndAppendLine(path, "PosAgreedByFirst" + output, str + "\t" + 1 + "\t" + 0);
					else 
						SequenceFileWriter.writeAndAppendLine(path, "NegAgreedBySecond" + output, str + "\t" + 1 + "\t" + 0);
				}
				else if(seq1 == false && seq2 == true) {
					SequenceFileWriter.writeAndAppendLine(path, output, str + "\t" + 0 + "\t" + 1);
					if(truth == 1) 
						SequenceFileWriter.writeAndAppendLine(path, "PosAgreedBySecond" + output, str + "\t" + 0 + "\t" + 1);
					else 
						SequenceFileWriter.writeAndAppendLine(path, "NegAgreedByFirst" + output, str + "\t" + 0 + "\t" + 1);
				}
				else {
					SequenceFileWriter.writeAndAppendLine(path, output, str + "\t" + 0 + "\t" + 0);
					if(truth == 1) 
						SequenceFileWriter.writeAndAppendLine(path, "PosDisagreedByBoth" + output, str + "\t" + 0 + "\t" + 0);
					else 
						SequenceFileWriter.writeAndAppendLine(path, "NegAgreedByBoth" + output, str + "\t" + 0 + "\t" + 0);
				}
			}
		} catch (Exception e) {
			System.out.println("GenerateSequencePairs failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void SeparateClustersFromGraphicalFormat(String path, String testFile, String fileName, String output) {
		try {
			String str;
			int count = -1;
			BufferedReader bufferedreader;
			ArrayList<String> lines = new ArrayList<String>();
			ArrayList<ArrayList<String>> families = new ArrayList<ArrayList<String>>();
			String currentFamily = "";
			bufferedreader = new BufferedReader(new FileReader(path + testFile));
			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				if(currentFamily.equals(strArr[2])) {
					families.get(count).add(strArr[1]);
				} else {
					ArrayList<String> family = new ArrayList<String>();
					family.add(strArr[1]);
					families.add(family);
					currentFamily = strArr[2];
					count++;
				}
			}
			bufferedreader.close();

			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) {
				if(str.startsWith("<?xml") || str.startsWith("<gexf") || str.startsWith("\t<meta") || str.startsWith("\t\t<creator") || str.startsWith("\t\t<description") || str.startsWith("\t</meta") || str.startsWith("</gexf")) {
					SequenceFileWriter.writeAndAppendLine(path, output + ".gexf", str);
					continue;
				} else if(!str.startsWith("\t</graph")) {
					lines.add(str);
				} else {
					lines.add(str);
					boolean check = false;

					outerloop:
						for(int i = 0; i < lines.size(); i++) {
							if(lines.get(i).startsWith("\t\t\t<node id=\"")) {
								for(int j = 0; j < families.size(); j++) {
									for(int k = 0; k < families.get(j).size(); k++) {
										if(lines.get(i).startsWith("\t\t\t<node id=\"" + families.get(j).get(k) + "\"")) {
											System.out.println("Cluster member " + families.get(j).get(k) + " found");
											check = true;
											break outerloop;
										}
									}
								}
							}
						}

					if(check == true) {
						for(int i = 0; i < lines.size(); i++) {
							boolean checker = false;
							if(lines.get(i).startsWith("\t\t\t<node id=\"")) {
								outerloop:
									for(int j = 0; j < families.size(); j++) {
										for(int k = 0; k < families.get(j).size(); k++) {
											if(lines.get(i).startsWith("\t\t\t<node id=\"" + families.get(j).get(k) + "\"")) {
												SequenceFileWriter.writeAndAppendString(path, output + ".bcl", j + "\t");
												SequenceFileWriter.writeAndAppendLine(path, output + ".gexf", lines.get(i));
												i++;
												SequenceFileWriter.writeAndAppendLine(path, output + ".gexf", lines.get(i));
												i++;
												SequenceFileWriter.writeAndAppendLine(path, output + ".gexf", "\t\t\t\t<viz:size value=\"50\"></viz:size>");
												i++;
												SequenceFileWriter.writeAndAppendLine(path, output + ".gexf", lines.get(i));
												i++;
												SequenceFileWriter.writeAndAppendLine(path, output + ".gexf", "\t\t\t\t<viz:color r=\"" + 255 + "\" g=\"" + 0 + "\" b=\"" + 0 + "\"></viz:color>");
												checker = true;
												break outerloop;
											}
										}
									}
								if(checker == false) {
									SequenceFileWriter.writeAndAppendLine(path, output + ".gexf", lines.get(i));
									i++;
									SequenceFileWriter.writeAndAppendLine(path, output + ".gexf", lines.get(i));
									i++;
									SequenceFileWriter.writeAndAppendLine(path, output + ".gexf", "\t\t\t\t<viz:size value=\"10\"></viz:size>");
									i++;
									SequenceFileWriter.writeAndAppendLine(path, output + ".gexf", lines.get(i));
									i++;
									SequenceFileWriter.writeAndAppendLine(path, output + ".gexf", "\t\t\t\t<viz:color r=\"" + 255 + "\" g=\"" + 255 + "\" b=\"" + 255 + "\"></viz:color>");
								}
							} else {
								SequenceFileWriter.writeAndAppendLine(path, output + ".gexf", lines.get(i));
							}
						}
						SequenceFileWriter.writeAndAppendLine(path, output + ".bcl", "");
					}
					while(lines.size()!= 0) 
						lines.remove(0);
				} 
			}
			bufferedreader.close();
		} catch (Exception e) {
			System.out.println("Error in SeparateClustersFromGraphicalFormat :" + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void ConvertGraphicalClustersToBlastClust(String path, String fileName, String output) {
		try {
			String str;
			BufferedReader bufferedreader;
			int count = 0;

			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) {
				if(str.startsWith("<?xml") || str.startsWith("<gexf") || str.startsWith("\t<meta") || str.startsWith("\t\t<creator") || str.startsWith("\t\t<description") || str.startsWith("\t</meta") || str.startsWith("</gexf")) {
					continue;
				} else if(str.startsWith("\t\t</nodes")) {
					while (!(str = bufferedreader.readLine()).startsWith("\t\t</edges")) {
						continue;
					}
				} else if(!str.startsWith("\t</graph")) {
					if(str.startsWith("\t\t\t<node id=\"")) {
						int j = 14;
						while(str.charAt(j)!='"') 
							j++;
						if(count == 0) {
							SequenceFileWriter.writeAndAppendString(path, output + ".bcl", str.substring(13, j));
							count++;
						} else {
							SequenceFileWriter.writeAndAppendString(path, output + ".bcl", "\t" + str.substring(13, j));
						}
					}
				} else {
					count = 0;
					SequenceFileWriter.writeAndAppendLine(path, output + ".bcl", "");
				} 
			}
			bufferedreader.close();
		} catch (Exception e) {
			System.out.println("Error in ConvertGraphicalClustersToBlastClust :" + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void ManagingYeastPillarsOriginal(String path, String syntenyFile, String pillarFileName, String syntenyScoreFile, String output) {
		try{
			String str;
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSyntenyFile(path, syntenyFile);
			ArrayList<Species> speciesList = reader.getSpeciesList();
			speciesList = reader.readNCandSyntenyFile(path, syntenyScoreFile, speciesList);
			System.out.println("Synteny file read.");
			BufferedReader bufferedreader = new BufferedReader(new FileReader(path + pillarFileName));
			int count = 0;
			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split("\t");
				System.out.println("Reading line " + count);
				for(int i = 0; i < strArr.length; i++) {
					if(!strArr[i].equals("-")) {
						int spec1 = Integer.parseInt(strArr[i].split("\\.")[0]);
						int chr1 = Integer.parseInt(strArr[i].split("\\.")[1]);
						int gene1 = Integer.parseInt(strArr[i].split("\\.")[2]);
						for(int j = i+1; j < strArr.length; j++) {
							if(!strArr[j].equals("-")) {
								boolean check = false;
								for(int k = 0; k < speciesList.get(spec1).getChromosomes().get(chr1).getGeneList().get(gene1).getGenencScore().size(); k++) {
									if(speciesList.get(spec1).getChromosomes().get(chr1).getGeneList().get(gene1).getGenencScore().get(k).first.equals(strArr[j])) {
										Couple<String, Float> ncScore = speciesList.get(spec1).getChromosomes().get(chr1).getGeneList().get(gene1).getGenencScore().get(k);
										float syntenyScore = speciesList.get(spec1).getChromosomes().get(chr1).getGeneList().get(gene1).getSyntenyScore().get(k);
										SequenceFileWriter.writeAndAppendLine(path, output, strArr[i] + "\t" + ncScore.first + "\t" + ncScore.second + "\t" + syntenyScore);
										check = true;
										break;
									}
								}
								if (check== false)
									SequenceFileWriter.writeAndAppendLine(path, "Notfoundpillars.tab", strArr[i] + "\t" + strArr[j]);
							}
						}
					}
				}
				count++;
			}
		} catch (Exception e) {
			System.out.println("Error: " + e.getMessage());
		}
	}
	
	public void ComparingYeastPillarsWithEvaluated(String path, String syntenyFile, String pillarFileName, String evaluatedScoreFile, String output) {
		try{
			String str;
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSyntenyFile(path, syntenyFile);
			System.out.println("Synteny file read.");
			ArrayList<Species> speciesList = reader.getSpeciesList();
			speciesList = reader.readEvaluationFile(path, evaluatedScoreFile, speciesList);
			System.out.println("Evaluated file read.");
			
			BufferedReader bufferedreader = new BufferedReader(new FileReader(path + pillarFileName));
			int count = 0;
			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split("\t");
				System.out.println("Reading line " + count);
/*				for(int i = 0; i < 32; i++) {
					boolean check = false;
					if(!strArr[i].equals("-")) {
						int spec1 = Integer.parseInt(strArr[i].split("\\.")[0]);
						int chr1 = Integer.parseInt(strArr[i].split("\\.")[1]);
						int gene1 = Integer.parseInt(strArr[i].split("\\.")[2]);
						outerloop:
							for(int j = 0; j < 32; j++) {
								if(i != j && !strArr[j].equals("-")) {
									for(int k = 0; k < speciesList.get(spec1).getChromosomes().get(chr1).getGeneList().get(gene1).getGenencScore().size(); k++) {
										if(speciesList.get(spec1).getChromosomes().get(chr1).getGeneList().get(gene1).getGenencScore().get(k).first.equals(strArr[j])) {
											SequenceFileWriter.writeAndAppendString(path, output, strArr[i] + "\t");
											check = true;
											break outerloop;
										}
									}
								}
							}
						if (check== false)
							SequenceFileWriter.writeAndAppendLine(path, "Notfoundpillars.tab", count + "\t" + strArr[i]);
					}
				}
				SequenceFileWriter.writeAndAppendString(path, output, "\n");
				count++;
*/				
				int counter = 0;
				for(int i = 0; i < 7; i++) {
					if(!strArr[i].equals("-")) {
						counter++;
					}
				}
				
				String[] strArr1 = new String[counter];
				int tempCounter = 0;
				for(int i = 0; i < 32; i++) {
					if(!strArr[i].equals("-")) {
						strArr1[tempCounter] = strArr[i];
						tempCounter++;
					}
				}
				for(int i = 0; i < counter; i++) {
					int spec1 = Integer.parseInt(strArr1[i].split("\\.")[0]);
					int chr1 = Integer.parseInt(strArr1[i].split("\\.")[1]);
					int gene1 = Integer.parseInt(strArr1[i].split("\\.")[2]);
					boolean check = false;
					outerloop:
						for(int k = 0; k < speciesList.get(spec1).getChromosomes().get(chr1).getGeneList().get(gene1).getGenencScore().size(); k++) {
							String eva = speciesList.get(spec1).getChromosomes().get(chr1).getGeneList().get(gene1).getGenencScore().get(k).first;
							for(int j = 0; j < counter; j++) {
								if(eva.equals(strArr[j])) {
									//SequenceFileWriter.writeAndAppendString(path, output, strArr[i] + "\t");
									check = true;
									break outerloop;
								}
							}
						}
					if (check== false)
						SequenceFileWriter.writeAndAppendLine(path, "AdditivePillars.tab", i + "\t" + strArr[i]);
				}
			}
		} catch (Exception e) {
			System.out.println("Error: " + e.getMessage());
		}
	}

	public void MapSyntenyIndexesToNames(String path, String fileName, String output) {
		try{
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSyntenyFile(path, fileName);
			ArrayList<Species> species = reader.getSpeciesList();
			for(int i = 0; i < species.size(); i++)
				for(int j = 0; j < species.get(i).getChromosomes().size(); j++)
					for(int k = 0; k < species.get(i).getChromosomes().get(j).getGeneList().size(); k++)
						SequenceFileWriter.writeAndAppendLine(path, output, i + "." + j + "." + k + "\t" + species.get(i).getChromosomes().get(j).getGeneList().get(k).getGeneID());
		} catch (Exception e) {
			System.out.println("Error: " + e.getMessage());
		}
	}
	
	public void ConstructPillarsUsingGFC(String path, String evaluatedFile, String output) {
		try {
			ArrayList<Pillar> pillars = new ArrayList<Pillar>();
			ArrayList<String> gene1 = new ArrayList<String>();
			ArrayList<String> gene2 = new ArrayList<String>();
			ArrayList<Float> evaScore = new ArrayList<Float>();
			BufferedReader bufferedreader;
			String line;
			
			bufferedreader = new BufferedReader(new FileReader(path + evaluatedFile));
			while ((line = bufferedreader.readLine()) != null) {
				String[] strArr = line.split("\t");
				if(!strArr[0].equals(strArr[1])) {
					gene1.add(strArr[0]);
					gene2.add(strArr[1]);
					evaScore.add(Float.parseFloat(strArr[2]));
				}
			}
			bufferedreader.close();
			
			System.out.println("Read the Evaluated File.");
			
			Float maxScore = (float) 0.995;
			for(int i = 0; i < gene1.size();) {	
				int temp = i;
				for(int j = i; j < gene1.size(); j++) {
					if(evaScore.get(j) > maxScore) {
						String tempGene1 = gene1.get(temp);
						String tempGene2 = gene2.get(temp);
						Float tempScore = evaScore.get(temp);
						gene1.set(temp, gene1.get(j));
						gene2.set(temp, gene2.get(j));
						evaScore.set(temp, evaScore.get(j));
						gene1.set(j, tempGene1);
						gene2.set(j, tempGene2);
						evaScore.set(j, tempScore);
						temp++;
					}
				}
				maxScore = (float) (maxScore - 0.005);
				i = temp;
				if(maxScore < 0.5)
					break;
			}
			
			System.out.println("Arranged the sequences hierarchically.");
			System.out.println("Gene1 size is " + gene1.size());
			
			for(int i = 0; i < gene1.size(); i++) {
				if(gene1.get(i).substring(0, 2).equals(gene2.get(i).substring(0, 2))) {
					SequenceFileWriter.writeAndAppendLine(path, "PossibleAlternatePillar.txt", gene1.get(i) + "\t" + gene2.get(i) + "\t" + evaScore.get(i));
				} else {
					int index1 = -1;
					int index2 = -1;
					for(int j = 0; j < pillars.size(); j++) {
						if(pillars.get(j).isPresent(gene1.get(i))) 
							index1 = j; 
						if(pillars.get(j).isPresent(gene2.get(i))) 
							index2 = j;
						if(index1 != -1 && index2 != -1)
							break;
					} 
					if(index1 == -1 && index2 == -1) {
						Pillar pillar = new Pillar();
						pillar.setPillar(gene1.get(i));
						pillar.setPillar(gene2.get(i));
						pillars.add(pillar);
					} else if(index1 != -1 && index2 == -1) {
						boolean check = pillars.get(index1).setPillar(gene2.get(i));
						if(check == false) 
							SequenceFileWriter.writeAndAppendLine(path, "TakenSlot.txt", "Already taken slot for gene2: " + gene1.get(i) + "\t" + gene2.get(i) + "\t" + evaScore.get(i));
					} else if (index1 == -1 && index2 != -1) {
						boolean check = pillars.get(index2).setPillar(gene1.get(i));
						if(check == false) 
							SequenceFileWriter.writeAndAppendLine(path, "TakenSlot.txt", "Already taken slot for gene1: " + gene1.get(i) + "\t" + gene2.get(i) + "\t" + evaScore.get(i));
					} else if (index1 != -1 && index2 != -1) 
						SequenceFileWriter.writeAndAppendLine(path, "EvidenceFound.txt", "Strengthened evidence for : " + gene1.get(i) + "\t" + gene2.get(i) + "\t" + evaScore.get(i));
				}
			}
			
			System.out.println("Total Pillars = " + pillars.size());
			
			for(int i = 0; i < pillars.size(); i++) {
				String[] pillar = pillars.get(i).getPillar();
				SequenceFileWriter.writeAndAppendString(path, output, pillar[0]);
				for(int j = 1; j < 20; j++) 
					SequenceFileWriter.writeAndAppendString(path, output, "\t" + pillar[j]);
				SequenceFileWriter.writeAndAppendLine(path, output, "");
			}
			System.out.println("Pillars Computed.");
		} catch (Exception e) {
			System.out.println("Error: " + e.getMessage());
		} 
	}
	
	public void CompareTwoClustersFromSoftware(String path, String software1, String software2, String output) {
		try {
			BufferedReader bufferedreader;
			String line;
			int proteins1 = 0;
			int proteins2 = 0;
			ArrayList<ArrayList<String>> software1Line = new ArrayList<ArrayList<String>>();
			ArrayList<ArrayList<String>> software2Line = new ArrayList<ArrayList<String>>();
			
			bufferedreader = new BufferedReader(new FileReader(path + software1));
			while ((line = bufferedreader.readLine()) != null) {
				String[] strArr = line.split("\t");
				if(strArr.length > 1) {
					ArrayList<String> prot = new ArrayList<String>();
					for(int i = 0; i < strArr.length; i++) 
						prot.add(strArr[i]);
					software1Line.add(prot);
					proteins1 = proteins1 + strArr.length;
				}
			}
			bufferedreader.close();
			
			bufferedreader = new BufferedReader(new FileReader(path + software2));
			while ((line = bufferedreader.readLine()) != null) {
				String[] strArr = line.split("\t");
				if(strArr.length > 1) {
					ArrayList<String> prot = new ArrayList<String>();
					for(int i = 0; i < strArr.length; i++) 
						prot.add(strArr[i]);
					software2Line.add(prot);
					proteins2 = proteins2 + strArr.length;
				}
			}
			bufferedreader.close();
			
			System.out.println("Number of Groups in Software 1 = " + software1Line.size());
			System.out.println("Number of Groups in Software 2 = " + software2Line.size());
			System.out.println("Number of Proteins in Software 1 = " + proteins1);
			System.out.println("Number of Proteins in Software 2 = " + proteins2);

			int common = 0;
			int acontainsb = 0;
			int bcontainsa = 0;
			int groupedbyboth = 0;
			int identicalgroups = 0;
			int protacontainsb1 = 0;
			int protacontainsb2 = 0;
			int protbcontainsa1 = 0;
			int protbcontainsa2 = 0;
			
			for(int i = 0; i < software1Line.size(); i++) {
				for(int j = 0; j < software2Line.size(); j++) {
					if(software1Line.get(i).containsAll(software2Line.get(j)) && software2Line.get(j).containsAll(software1Line.get(i))) {
						common++;
						identicalgroups = identicalgroups + software1Line.get(i).size();
						groupedbyboth = groupedbyboth + software1Line.get(i).size();
						break;
					}
				}
			}
			System.out.println("Common count = " + common);
			
			
			int countA = 0;
			int countB = 0;
			for(int i = 0; i < software1Line.size(); i++) {
				int name = -1;
				for(int j = 0; j < software2Line.size(); j++) {
					if(software1Line.get(i).containsAll(software2Line.get(j)) && !software2Line.get(j).containsAll(software1Line.get(i))) {
						groupedbyboth = groupedbyboth + software2Line.get(j).size();
						acontainsb++;
						protacontainsb2 = protacontainsb2 + software2Line.get(j).size();
						if(name != i) {
							protacontainsb1 = protacontainsb1 + software1Line.get(i).size();
							countA++;
							name = i;
						}
					}
				}
			}
			
			System.out.println("A contains B = " + acontainsb + " countA = " + countA);
			
			for(int j = 0; j < software2Line.size(); j++) {
				int name = -1;
				for(int i = 0; i < software1Line.size(); i++) {
					if(!software1Line.get(i).containsAll(software2Line.get(j)) && software2Line.get(j).containsAll(software1Line.get(i))) {
						bcontainsa++;
						groupedbyboth = groupedbyboth + software1Line.get(i).size();
						protbcontainsa2 = protbcontainsa2 + software1Line.get(i).size();
						if(name != j) {
							countB++;
							protbcontainsa1 = protbcontainsa1 + software2Line.get(j).size();
							name = j;
						} 
					}
				}
			}
			System.out.println("B contains A = " + bcontainsa + " countB = " + countB);
			System.out.println("Grouped by both = " + groupedbyboth);
			System.out.println("Identical Groups = " + identicalgroups);
			System.out.println("A contains B first = " + protacontainsb1);
			System.out.println("A contains B second = " + protacontainsb2);
			System.out.println("B contains A first = " + protbcontainsa1);
			System.out.println("B contains A second = " + protbcontainsa2);
		} catch (Exception e) {
			System.out.println("Error: " + e.getMessage());
		} 
	}
	
	public void ExtractHumanMouseClusters(String path, String fileName, String output) {
		try {
			BufferedReader bufferedreader;
			String line;
			
			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((line = bufferedreader.readLine()) != null) {
				String[] strArr = line.split("\t");
				boolean check = false;
				for(int i = 0; i < strArr.length; i++) {
					if(strArr[i].startsWith("17.") || strArr[i].startsWith("18.")) 
						if(check == false) {
							SequenceFileWriter.writeAndAppendString(path, output, strArr[i]);
							check = true;
						} else
							SequenceFileWriter.writeAndAppendString(path, output, "\t" + strArr[i]);
				}
				if(check == true)
					SequenceFileWriter.writeAndAppendLine(path, output, "");
			}
			bufferedreader.close();
		} catch (Exception e) {
			System.out.println("Error: " + e.getMessage());
		} 
	}
	
	public void DrawDotPlot(String path, String syntenyFile, String software1, String software2, String output) {
		try {
			BufferedReader bufferedreader;
			ArrayList<ArrayList<String>> ygob = new ArrayList<ArrayList<String>>();
			ArrayList<ArrayList<String>> myPillars = new ArrayList<ArrayList<String>>();
			String line;

			bufferedreader = new BufferedReader(new FileReader(path + software1));
			while ((line = bufferedreader.readLine()) != null) {
				String[] strArr = line.split("\t");
				ArrayList<String> list = new ArrayList<String>();
				for(int i = 0; i < strArr.length; i++) 
					list.add(strArr[i]);
				ygob.add(list);
			}
			bufferedreader.close();
			System.out.println("YGOB read");
			
			bufferedreader = new BufferedReader(new FileReader(path + software2));
			while ((line = bufferedreader.readLine()) != null) {
				String[] strArr = line.split("\t");
				ArrayList<String> list = new ArrayList<String>();
				for(int i = 0; i < strArr.length; i++) 
					list.add(strArr[i]);
				myPillars.add(list);
			}
			bufferedreader.close();
			System.out.println("GFC read");
			
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSyntenyFile(path, syntenyFile);
			
			ArrayList<Species> species = reader.getSpeciesList();
			
			for(int i = 0; i < ygob.size(); i++) {
				for(int j = 0; j < ygob.get(i).size(); j++) {
					String[] strArr1 = ygob.get(i).get(j).split("\\.");
					for(int k = j+1; k < ygob.get(i).size(); k++) {
						String[] strArr = ygob.get(i).get(k).split("\\.");
						species.get(Integer.parseInt(strArr1[0])).getChromosomes().get(Integer.parseInt(strArr1[1])).getGeneList().get(Integer.parseInt(strArr1[2])).insertYGOBPillar(species.get(Integer.parseInt(strArr[0])).getChromosomes().get(Integer.parseInt(strArr[1])).getGeneList().get(Integer.parseInt(strArr[2])).getPositionInCluster());
						species.get(Integer.parseInt(strArr[0])).getChromosomes().get(Integer.parseInt(strArr[1])).getGeneList().get(Integer.parseInt(strArr[2])).insertYGOBPillar(species.get(Integer.parseInt(strArr1[0])).getChromosomes().get(Integer.parseInt(strArr1[1])).getGeneList().get(Integer.parseInt(strArr1[2])).getPositionInCluster());
					}
				}
			}
			System.out.println("YGOB added.");
			
			for(int i = 0; i < myPillars.size(); i++) {
				for(int j = 0; j < myPillars.get(i).size(); j++) {
					String[] strArr1 = myPillars.get(i).get(j).split("\\.");
					for(int k = j+1; k < myPillars.get(i).size(); k++) {
						String[] strArr = myPillars.get(i).get(k).split("\\.");
						species.get(Integer.parseInt(strArr1[0])).getChromosomes().get(Integer.parseInt(strArr1[1])).getGeneList().get(Integer.parseInt(strArr1[2])).insertMyPillar(species.get(Integer.parseInt(strArr[0])).getChromosomes().get(Integer.parseInt(strArr[1])).getGeneList().get(Integer.parseInt(strArr[2])).getPositionInCluster());
						species.get(Integer.parseInt(strArr[0])).getChromosomes().get(Integer.parseInt(strArr[1])).getGeneList().get(Integer.parseInt(strArr[2])).insertMyPillar(species.get(Integer.parseInt(strArr1[0])).getChromosomes().get(Integer.parseInt(strArr1[1])).getGeneList().get(Integer.parseInt(strArr1[2])).getPositionInCluster());
					}
				}
			}
			System.out.println("GFC added");
			
			for(int i = 0; i < species.size(); i++) {
				for(int j = 0; j < species.get(i).getChromosomes().size(); j++) {
					for(int k = 0; k < species.get(i).getChromosomes().get(j).getGeneList().size(); k++) {
						Integer gene = species.get(i).getChromosomes().get(j).getGeneList().get(k).getPositionInCluster() + 1;
						ArrayList<Integer> ygobPillar = species.get(i).getChromosomes().get(j).getGeneList().get(k).getYGOBPillars();
						ArrayList<Integer> myPillar = species.get(i).getChromosomes().get(j).getGeneList().get(k).getMyPillars();
						if(ygobPillar.containsAll(myPillar) && myPillar.containsAll(ygobPillar)) {
							for(int l = 0; l < ygobPillar.size(); l++) {
								Integer hit = ygobPillar.get(l) + 1 ;
								SequenceFileWriter.writeAndAppendLine(path, "Common" + output, gene + "\t" + hit);
							}
						} else if(ygobPillar.containsAll(myPillar)) {
							for(int l = 0; l < myPillar.size(); l++) {
								Integer hit = myPillar.get(l) + 1 ;
								SequenceFileWriter.writeAndAppendLine(path, "Common" + output, gene + "\t" + hit);
								species.get(i).getChromosomes().get(j).getGeneList().get(k).removeYGOBPillar(hit);
							}
							
							ygobPillar = species.get(i).getChromosomes().get(j).getGeneList().get(k).getYGOBPillars();
							for(int l = 0; l < ygobPillar.size(); l++) {
								Integer hit = ygobPillar.get(l) + 1 ;
								SequenceFileWriter.writeAndAppendLine(path, "UniqueYGOB" + output, gene + "\t" + hit);
							}
						} else if(myPillar.containsAll(ygobPillar)) {
							for(int l = 0; l < ygobPillar.size(); l++) {
								Integer hit = ygobPillar.get(l) + 1 ;
								SequenceFileWriter.writeAndAppendLine(path, "Common" + output, gene + "\t" + hit);
								species.get(i).getChromosomes().get(j).getGeneList().get(k).removeMyPillar(hit);
							}
							
							myPillar = species.get(i).getChromosomes().get(j).getGeneList().get(k).getMyPillars();
							for(int l = 0; l < myPillar.size(); l++) {
								Integer hit = myPillar.get(l) + 1 ;
								SequenceFileWriter.writeAndAppendLine(path, "UniqueGFC" + output, gene + "\t" + hit);
							}
						} else {
							for(int l = 0; l < ygobPillar.size(); l++) {
								Integer hit = ygobPillar.get(l) + 1 ;
								SequenceFileWriter.writeAndAppendLine(path, "Common" + output, gene + "\t" + hit);
								species.get(i).getChromosomes().get(j).getGeneList().get(k).removeMyPillar(hit);
								species.get(i).getChromosomes().get(j).getGeneList().get(k).removeYGOBPillar(hit);
							}
							
							myPillar = species.get(i).getChromosomes().get(j).getGeneList().get(k).getMyPillars();
							for(int l = 0; l < myPillar.size(); l++) {
								Integer hit = myPillar.get(l) + 1 ;
								SequenceFileWriter.writeAndAppendLine(path, "UniqueGFC" + output, gene + "\t" + hit);
							}
							
							ygobPillar = species.get(i).getChromosomes().get(j).getGeneList().get(k).getYGOBPillars();
							for(int l = 0; l < ygobPillar.size(); l++) {
								Integer hit = ygobPillar.get(l) + 1 ;
								SequenceFileWriter.writeAndAppendLine(path, "UniqueYGOB" + output, gene + "\t" + hit);
							}
						}
					}
				}
			}			
			System.out.println("GFC Unique done");
		} catch (Exception e) {
			System.out.println("Error: " + e.getMessage());
		} 
	}
	
	public void getSequenesFromIdentifier(String path, String fileName, String sequenceFile, String output) {
		try {
			String line;
			BufferedReader bufferedreader = new BufferedReader(new FileReader(path + fileName));
			line = bufferedreader.readLine();
			String[] strArr = line.split("\t");
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSequenceFile(path, sequenceFile);
			ArrayList<Sequence> sequences = reader.getSequences();
			for(int i = 0; i < strArr.length; i++) {
				for(int j = 0; j < sequences.size(); j++) {
					if(sequences.get(j).getIdentifier().equals(strArr[i])) {
						String[] strArr1 = strArr[i].split("\\.");
						if(strArr1[0].equals("0"))
							strArr[i] = "Cgl" + strArr[i];
						else if(strArr1[0].equals("1"))
							strArr[i] = "Ecy" + strArr[i];
						else if(strArr1[0].equals("2"))
							strArr[i] = "Ego" + strArr[i];
						else if(strArr1[0].equals("3"))
							strArr[i] = "Kaf" + strArr[i];
						else if(strArr1[0].equals("4"))
							strArr[i] = "Kla" + strArr[i];
						else if(strArr1[0].equals("5"))
							strArr[i] = "Kan" + strArr[i];
						else if(strArr1[0].equals("6"))
							strArr[i] = "Lkl" + strArr[i];
						else if(strArr1[0].equals("7"))
							strArr[i] = "Lth" + strArr[i];
						else if(strArr1[0].equals("8"))
							strArr[i] = "Lwa" + strArr[i];
						else if(strArr1[0].equals("9"))
							strArr[i] = "Nca" + strArr[i];
						else if(strArr1[0].equals("10"))
							strArr[i] = "Nda" + strArr[i];
						else if(strArr1[0].equals("11"))
							strArr[i] = "Sce" + strArr[i];
						else if(strArr1[0].equals("12"))
							strArr[i] = "Sku" + strArr[i];
						else if(strArr1[0].equals("13"))
							strArr[i] = "Smi" + strArr[i];
						else if(strArr1[0].equals("14"))
							strArr[i] = "Suv" + strArr[i];
						else if(strArr1[0].equals("15"))
							strArr[i] = "Tbl" + strArr[i];
						else if(strArr1[0].equals("16"))
							strArr[i] = "Tde" + strArr[i];
						else if(strArr1[0].equals("17"))
							strArr[i] = "Tph" + strArr[i];
						else if(strArr1[0].equals("18"))
							strArr[i] = "Vpo" + strArr[i];
						else if(strArr1[0].equals("19"))
							strArr[i] = "Zro" + strArr[i];
						Sequence seq = new Sequence(strArr[i], sequences.get(j).getSequence());
						SequenceFileWriter.writeAndAppendSequenceInFasta(path, output, seq);
						break;
					}
				}
			}
		} catch (Exception e) {
			
		}
	}
	
	public void DetermineYeastPillarMatching(String path, String software1, String software2, String output) {
		try {
			String line;
			ArrayList<ArrayList<String>> ygobPillars = new ArrayList<ArrayList<String>>();
			ArrayList<ArrayList<String>> gfcPillars = new ArrayList<ArrayList<String>>();
			BufferedReader bufferedreader = new BufferedReader(new FileReader(path + software1));
			while ((line = bufferedreader.readLine()) != null) {
				ArrayList<String> list = new ArrayList<String>();
				String[] strArr = line.split("\t");
				for(int i = 0; i < strArr.length; i++) 
					list.add(strArr[i]);
				ygobPillars.add(list);
			}
			bufferedreader.close();
			
			bufferedreader = new BufferedReader(new FileReader(path + software2));
			while ((line = bufferedreader.readLine()) != null) {
				ArrayList<String> list = new ArrayList<String>();
				String[] strArr = line.split("\t");
				for(int i = 0; i < strArr.length; i++) 
					list.add(strArr[i]);
				gfcPillars.add(list);
			}
			bufferedreader.close();
			
			for(int i = 0; i < gfcPillars.size(); i++) {
				ArrayList<String> gfclist = gfcPillars.get(i);
				boolean clash = true;
				for(int j = 0; j < ygobPillars.size(); j++) {
					ArrayList<String> ygoblist = ygobPillars.get(j);
					if(gfclist.containsAll(ygoblist) && ygoblist.containsAll(gfclist)) {
						SequenceFileWriter.writeAndAppendString(path, "Equal" + output, gfclist.get(0));
						for(int k = 1; k < gfclist.size(); k++)
							SequenceFileWriter.writeAndAppendString(path, "Equal" + output, "\t" + gfclist.get(k));
						SequenceFileWriter.writeAndAppendString(path, "Equal" + output, "\n");
						clash = false;
						ygobPillars.remove(j);
						break;
					} else if (gfclist.containsAll(ygoblist)) {
						if(clash == true) {
							SequenceFileWriter.writeAndAppendString(path, "GFCSuperset" + output, "\n\n" + gfclist.get(0));
							for(int k = 1; k < gfclist.size(); k++) 
								SequenceFileWriter.writeAndAppendString(path, "GFCSuperset" + output, "\t" + gfclist.get(k));

							SequenceFileWriter.writeAndAppendLine(path, "GFCSuperset" + output, "");
						}
						SequenceFileWriter.writeAndAppendString(path, "GFCSuperset" + output, ygoblist.get(0));
						for(int k = 1; k < ygoblist.size(); k++) 
							SequenceFileWriter.writeAndAppendString(path, "GFCSuperset" + output, "\t" + ygoblist.get(k));
						SequenceFileWriter.writeAndAppendLine(path, "GFCSuperset" + output, "");
						clash = false;
					} else if (ygoblist.containsAll(gfclist)) {
						SequenceFileWriter.writeAndAppendString(path, "YGOBSuperset" + output, "\n\n" + ygoblist.get(0));
						for(int k = 1; k < ygoblist.size(); k++) 
							SequenceFileWriter.writeAndAppendString(path, "YGOBSuperset" + output, "\t" + ygoblist.get(k));
						SequenceFileWriter.writeAndAppendLine(path, "YGOBSuperset" + output, "");

						SequenceFileWriter.writeAndAppendString(path, "YGOBSuperset" + output, gfclist.get(0));
						for(int k = 1; k < gfclist.size(); k++) 
							SequenceFileWriter.writeAndAppendString(path, "YGOBSuperset" + output, "\t" + gfclist.get(k));
						SequenceFileWriter.writeAndAppendLine(path, "YGOBSuperset" + output, "");
						clash = false;
						break;
					}
				}
				if(clash == true) {
					SequenceFileWriter.writeAndAppendString(path, "Clash" + output, "\n\n" + gfclist.get(0));
					for(int k = 1; k < gfclist.size(); k++) 
						SequenceFileWriter.writeAndAppendString(path, "Clash" + output, "\t" + gfclist.get(k));

					SequenceFileWriter.writeAndAppendLine(path, "Clash" + output, "");
					
					for(int j = 0; j < gfclist.size(); j++) {
						for(int k = 0; k < ygobPillars.size(); k++) {
							if(ygobPillars.get(k).contains(gfclist.get(j))) {
								ArrayList<String> ygoblist = ygobPillars.get(k);
								SequenceFileWriter.writeAndAppendString(path, "Clash" + output, ygoblist.get(0));
								for(int l = 1; l < ygoblist.size(); l++) 
									SequenceFileWriter.writeAndAppendString(path, "Clash" + output, "\t" + ygoblist.get(l));

								SequenceFileWriter.writeAndAppendLine(path, "Clash" + output, "");
							}
						}
					}
				}
			}
		} catch (Exception e) {
			
		}
	}
	
	public void DetermineAPBHomologyClusters(String path, String fileName, String output) {
		try {
			String line;
			int count77 = 0;
			int count78 = 0;
			int count79 = 0;
			int count81 = 0;
			int totalcount = 0;
			int clustercount = 0;
			
			BufferedReader bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((line = bufferedreader.readLine()) != null) {
				String[] strArr = line.split("\t");
				boolean check = false;
				boolean check2 = false;
				boolean check3 = false;
				boolean check4 = false;
				for(int i = 0; i < strArr.length; i++) {
					String[] strArr1 = strArr[i].split("\\.");
					if(check == true && (!(strArr1[0].equals("77") || strArr1[0].equals("78") || strArr1[0].equals("79") || strArr1[0].equals("81")))) {
						check2 = true;
						break;
					} else if(check == false && (!(strArr1[0].equals("77") || strArr1[0].equals("78") || strArr1[0].equals("79") || strArr1[0].equals("81")))) {
						check = true;
					}
				}
				
				if(check2 == true) {
					for(int i = 0; i < strArr.length; i++) {
						String[] strArr1 = strArr[i].split("\\.");
						if(check3 == true && ((strArr1[0].equals("77") || strArr1[0].equals("78") || strArr1[0].equals("79") || strArr1[0].equals("81")))) {
							check4 = true;
							break;
						} else if(check3 == false && ((strArr1[0].equals("77") || strArr1[0].equals("78") || strArr1[0].equals("79") || strArr1[0].equals("81")))) {
							check3 = true;
						}
					}
				}
				
				if(check4 == true) {
					clustercount++;
					for(int i = 0; i < strArr.length; i++) {
						String[] strArr1 = strArr[i].split("\\.");
						if(strArr1[0].startsWith("77")) {
							count77++;
						} else if(strArr1[0].startsWith("78")) {
							count78++;
						} else if(strArr1[0].startsWith("79")) {
							count79++;
						} else if(strArr1[0].startsWith("81")) {
							count81++;
						}
						totalcount++;
					}
				}
			}
			System.out.println(count77);
			System.out.println(count78);
			System.out.println(count79);
			System.out.println(count81);
			int homolog = count77 + count78 + count79 + count81;
			System.out.println("Total genes = " + homolog);
			System.out.println("Total homologs = " + totalcount);
			System.out.println(clustercount);
			bufferedreader.close();
		} catch (Exception e) {
			
		}
	}
	
	public void APBQueryQueryBlast(String path, String fileName, String output) {
		try {
			String line;
			
			BufferedReader bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((line = bufferedreader.readLine()) != null) {
				String[] strArr = line.split("\t");
				String[] strArr1 = strArr[0].split("\\.");
				String[] strArr2 = strArr[1].split("\\.");
				if(Integer.parseInt(strArr1[0]) > 67)
					if(Integer.parseInt(strArr2[0]) > 67)
						SequenceFileWriter.writeAndAppendLine(path, output, line);
			}
			bufferedreader.close();
		} catch (Exception e) {
			
		}
	}
	
	public void SimulatedDataGoldStandardConverter(String path, String syntenyFile, String fileName, String output) {
		try{
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSyntenyFile(path, syntenyFile);
			System.out.println("File read");
			ArrayList<Species> speciesList = reader.getSpeciesList();
			
			BufferedReader bufferedreader;
			String str;
			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			
			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				for(int h = 0; h < strArr.length; h++) {
					outerloop:
					for(int i = 0; i < speciesList.size(); i++) {
						for(int j = 0; j < speciesList.get(i).getChromosomes().size(); j++) {
							for(int k = 0; k < speciesList.get(i).getChromosomes().get(j).getGeneList().size(); k++) {
								if(strArr[h].equals(speciesList.get(i).getChromosomes().get(j).getGeneList().get(k).getGeneID())) {
									if(h==0)
										SequenceFileWriter.writeAndAppendString(path, output, speciesList.get(i).getChromosomes().get(j).getGeneList().get(k).getIndex());
									else
										SequenceFileWriter.writeAndAppendString(path, output, "\t" + speciesList.get(i).getChromosomes().get(j).getGeneList().get(k).getIndex());
									break outerloop;
								}
							}
						}
					}
				}
				SequenceFileWriter.writeAndAppendLine(path, output, "");
			}
		} catch(Exception e) {
			System.out.println("SimulatedDataGoldStandardConverter failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void PrepareHashimsTestFormatFiles(String path, String syntenyFile, String fileName, String output) {
		try{
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSyntenyFile(path, syntenyFile);
			System.out.println("File read");
			ArrayList<Species> speciesList = reader.getSpeciesList();
			
			BufferedReader bufferedreader;
			String str;
			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			int count = 0;
			
			while ((str = bufferedreader.readLine()) != null) {
				count++;
				String[] strArr = str.split("\t");
				for(int h = 0; h < strArr.length; h++) {
					outerloop:
					for(int i = 0; i < speciesList.size(); i++) {
						for(int j = 0; j < speciesList.get(i).getChromosomes().size(); j++) {
							for(int k = 0; k < speciesList.get(i).getChromosomes().get(j).getGeneList().size(); k++) {
								if(strArr[h].equals(speciesList.get(i).getChromosomes().get(j).getGeneList().get(k).getGeneID())) {
									SequenceFileWriter.writeAndAppendLine(path, output, strArr[h] + "\t" + speciesList.get(i).getChromosomes().get(j).getGeneList().get(k).getIndex() + "\t" + count);
									break outerloop;
								}
							}
						}
					}
				}
			}
		} catch(Exception e) {
			System.out.println("PrepareHashimsTestFormatFiles failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void GeneratePairsFromClusters(String path, String fileName, String output) {
		try{
			BufferedReader bufferedreader;
			String str;
			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			
			while ((str = bufferedreader.readLine()) != null) {
				String[] strArr = str.split("\t");
				if(strArr.length == 2)
					if(!strArr[0].equals("-") && !strArr[1].equals("-")) {
						SequenceFileWriter.writeAndAppendLine(path, output, str);
						SequenceFileWriter.writeAndAppendLine(path, output, strArr[1] + "\t" + strArr[0]);
					}
					else {
					}
				else if (strArr.length > 2) {
					for(int i = 0; i < strArr.length; i++) {
						if(!strArr[i].equals("-")) {
							for(int j = 0; j < strArr.length; j++) {
								if(!strArr[j].equals("-") && i != j) {
									SequenceFileWriter.writeAndAppendLine(path, output, strArr[i] + "\t" + strArr[j]);
								}
							}
						}
					}
				} else {
					
				}
			}
		} catch(Exception e) {
			System.out.println("GeneratePairsFromClusters failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void CompareTwoPairsFiles(String path, String software1, String software2, String output) {
		try{
			BufferedReader bufferedreader;
			String str;
			ArrayList<String> sw2 = new ArrayList<String>();
			bufferedreader = new BufferedReader(new FileReader(path + software2));
			
			while ((str = bufferedreader.readLine()) != null) {
				sw2.add(str);
			}
			bufferedreader.close();
			
			bufferedreader = new BufferedReader(new FileReader(path + software1));
			int foundcount = 0;
			int unfoundcount = 0;
			int total = 0;
			
			while ((str = bufferedreader.readLine()) != null) {
				boolean check = false;
				total++;
				for(int i = 0; i < sw2.size(); i++) {
					if(str.equals(sw2.get(i))) {
						check = true;
						foundcount++;
						SequenceFileWriter.writeAndAppendLine(path, "Found" + output, str);
						break;
					}
				}
				if(check == false) {
					SequenceFileWriter.writeAndAppendLine(path, "Not Found" + output, str);
					unfoundcount++;
				}
			}
			bufferedreader.close();
			
			System.out.println("Total = " + total);
			System.out.println("Found = " + foundcount);
			System.out.println("Not found = " + unfoundcount);
		} catch(Exception e) {
			System.out.println("GeneratePairsFromClusters failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void ExtractNCSpeciesHits(String path, String fileName, String output) {
		BufferedReader bufferedreader;
		String str;
		try {
			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split(" ");
				String[] strArr1 = strArr[0].split("\\.");
				String[] strArr2 = strArr[1].split("\\.");
				if(strArr1[0].equals(strArr2[0])) {
					SequenceFileWriter.writeAndAppendLine(path, "NCSp" + strArr1[0] + ".nnc", str);
				} else {
					SequenceFileWriter.writeAndAppendLine(path, "NCSp" + strArr1[0] + ".nnc", str);
					SequenceFileWriter.writeAndAppendLine(path, "NCSp" + strArr2[0] + ".nnc", str);
				}
			}
			bufferedreader.close();
		} catch (Exception e) {
			System.out.println("CorrectBlastResults failed : " + e.getMessage());
			System.exit(-1);
		}
	}
	
	public void ApplyNCThreshold(String path, String fileName, String output) {
		BufferedReader bufferedreader;
		String str;
		try {
			bufferedreader = new BufferedReader(new FileReader(path + fileName));
			while ((str = bufferedreader.readLine()) != null) { 
				String[] strArr = str.split("\t");
				if(Float.parseFloat(strArr[2]) > 0.3) {
					SequenceFileWriter.writeAndAppendLine(path, output, str);
				}
			}
			bufferedreader.close();
		} catch (Exception e) {
			System.out.println("NCThreshold failed : " + e.getMessage());
			System.exit(-1);
		}
	}
}
